<template>
	<view class="company-info">
		<view class="base-info">
			<view class="company-name">{{needInfo.customerName}}</view>
			<view class="u-flex u-row-between">
				<view>信贷管家：{{needInfo.userName}}</view>
				<u-tag v-if="needInfo.enabledMark==0" type="error" mode="dark" text="已终止"></u-tag>
			</view>
		</view>
		<view>
			<mescroll-body ref="mescrollRef" safearea @init="mescrollInit" @down="downCallback" @up="upCallback">
				<view class="order">
					<u-time-line>
						<u-time-line-item :nodeTop="index+1" v-for="(item,index) in dataList" :key="index">
							<!-- 此处自定义了左边内容，用一个图标替代 -->
							<template v-slot:node>
								<view class="u-node" style="background: #19be6b;">
									<!-- 此处为uView的icon组件 -->
									<u-icon name="pushpin-fill" color="#fff" :size="24"></u-icon>
								</view>
							</template>
							<template v-slot:content>
								<view>
									<view class="u-flex u-row-between">
										<view class="u-order-title">
											服务费：{{item.amount}}元
										</view>
										<view>
											<u-tag type="warning" size="mini" v-if="item.type==0" text="待审核"></u-tag>
											<u-tag type="success" size="mini" v-if="item.type==1" text="已通过"></u-tag>
										</view>
									</view>
									<view class="u-order-time">操作人：{{item.creatorUser}}</view>
									<view class="u-order-time-2">创建时间：{{item.creatorTime}}</view>
									<view>
										<JSGJImages :imagesList="item.attachmentList"></JSGJImages>
									</view>
								</view>
							</template>
						</u-time-line-item>
					</u-time-line>
				</view>
			</mescroll-body>
		</view>
		<view class="save-bottom" v-if="needInfo.enabledMark==1">
			<view class="fixed-btn save-padding">
				<u-button class="btn-box" @click="applyWithdrawal" type="warning">续费</u-button>
				<u-button class="btn-box" @click="jujue(needInfo.id)" type="error">终止</u-button>
			</view>
		</view>
		<!-- 申请提现弹窗 -->
		<u-popup v-model="showWithdrawalPopup" mode="center" :mask="true" width="90%" height="800rpx"
			border-radius="20">
			<view class="withdrawal-popup" style="margin: 20rpx;">
				<u-form :model="formData" ref="uForm" class="uForm" label-position="top">
					<u-form-item prop="withdrawalAmount" label="续费" label-width="auto">
						<u-input v-model="formData.withdrawalAmount" border="true" placeholder="请输入信息服务费"
							@click="show = true" />
					</u-form-item>
					<u-form-item prop="images" label="附件信息" label-width="auto">
						<JNPFUpload v-model="attendanceFileList" :value="attendanceFileList" :fileSize='2' :limit='10'
							:showLabel="false" @uploading="uploading">
						</JNPFUpload>
					</u-form-item>
				</u-form>
				<view class="button-group" style="padding-top: 30rpx;">
					<u-button type="primary" size="medium" :disabled="btnDisabled"
						@click="submitWithdrawal">提交</u-button>
					<u-button size="medium" @click="showWithdrawalPopup = false">取消</u-button>
				</view>
			</view>
		</u-popup>
	</view>

</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

	import config from '@/common/js/config.js'
	export default {
		components: {

		},
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)

		data() {
			return {
				needInfo: {},
				showWithdrawalPopup: false,
				userinfo: {},
				dataList: [],

				current: 0,
				demandId: null,
				companyInfo: {},
				formData: {
					withdrawalAmount: '',
					attachmentInfo: ''
				},
				btnDisabled: false,
				attendanceFileList: [],
				uuid: ""
			}
		},
		onLoad(options) {
			if (options.id) {
				this.demandId = options.id
				this.init()
			}
			if (options.uuid) {
				this.uuid = options.uuid
			}
			const userProvider = uni.getStorageSync(config.Global.cache + '_UserProvider');
			this.userinfo = userProvider;
		},
		methods: {
			uploading(flag) {
				this.btnDisabled = flag
			},
			upCallback(page) {
				let httpData = {
					currentPage: page.num,
					pageSize: page.size,
					uuid: this.uuid,
					sidx: 'CreatorTime'
				}
				this.$helper.ajax({
					url: `/api/Jiushi/Customerconsultantdetail`,
					method: 'GET',
					data: httpData,
					success: res => {
						console.log(res)
						let curPageLen = res.data.data.list.length;
						let totalSize = res.data.data.pagination.total;
						this.mescroll.endBySize(curPageLen, totalSize);
						if (page.num == 1) {
							this.dataList = []
						}
						let tempList = res.data.data.list.map(item => {
							item.attachmentList = item.attachmentInfo == null || item.attachmentInfo ==
								'' ? [] : item
								.attachmentInfo.split(',')
							return item
						})
						this.dataList = this.dataList.concat(tempList);
					}
				});
			},
			applyWithdrawal() {
				this.showWithdrawalPopup = true;
			},
			submitWithdrawal() {
				if (this.formData.withdrawalAmount) {

					this.formData.attachmentInfo = this.attendanceFileList.map(item => {
						return item.url
					}).join(',')

					let url = "/api/Jiushi/Customerconsultant";
					let method = "POST";
					this.$helper.ajax({
						url: url,
						method: method,
						contentType: "application/json",
						data: {
							amount: this.formData.withdrawalAmount,
							id: this.needInfo.id,
							customerId: this.needInfo.customerId,
							attachmentInfo: this.formData.attachmentInfo
						},
						success: res => {
							this.$helper.msg(res.data.msg, 'success');
							this.init();
							this.mescroll.resetUpScroll();
						},
						fail: res => {

						}
					});
					this.showWithdrawalPopup = false;
					this.withdrawalAmount = '';
				} else {
					uToast({
						type: 'error',
						message: '请输入提现金额'
					});
				}
			},
			init() {
				this.$helper.ajax({
					url: "/api/Jiushi/Customerconsultant/" + this.demandId,
					method: "GET",
					contentType: "application/json",
					success: res => {
						this.needInfo = res.data.data
					}
				});
			},
			change(index) {
				this.current = index;
			},
			jujue(id) {
				let url = "/api/Jiushi/Customerconsultant/End/" + id;
				let method = "POST";
				this.$helper.ajax({
					url: url,
					method: method,
					contentType: "application/json",
					success: res => {
						this.init()
						this.$helper.msg(res.data.msg, 'success');
					}
				});
			},
			handleDetail(detail) {
				let url = '../subpage/addloan?bankUserId=' + detail.accountManagerUserId + '&customerId=' + this.needInfo
					.customerId + '&recordId=' + detail.id +
					'&needId=' + this.needInfo.id
				uni.navigateTo({
					url: url
				})

			},
			showlorndetail(detail) {
				let url = '../subpage/loandetaillist?customerNeedRecordId=' + detail.id;
				uni.navigateTo({
					url: url
				})

			},


			callGuan(phone) {

				if (this.userinfo.roleName.indexOf('客户经理') == -1) {
					return;

				}
				uni.makePhoneCall({
					phoneNumber: phone,

					success() {
						let url = "/api/Jiushi/Customerneedrecord";
						let method = "POST";
						this.$helper.ajax({
							url: url,
							method: method,
							contentType: "application/json",
							data: {
								customerNeedId: this.needInfo.id,
								customerId: this.needInfo.customerId
							},
							success: res => {

								this.$helper.msg(res.data.msg, 'success');
								this.mescroll.resetUpScroll();

							}
						});

					}

				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.company-info {
		.base-info {
			background-color: #3281ff;
			padding: 24rpx;
			height: auto;
			color: #fff;
			font-size: 28rpx;

			.company-name {
				font-size: 32rpx;
				font-weight: 600;
			}
		}
	}

	.content {
		padding: 60upx 40upx;
		font-size: 28upx;
		line-height: 48upx;
	}

	.fixed-btn {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		gap: 20rpx;

		.btn-box {
			flex: 1;
		}
	}
</style>


<style lang="scss" scoped>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;
	}

	.top {
		display: flex;
		justify-content: space-between;
	}

	.left {
		display: flex;
		align-items: center;
	}

	.store {
		margin-right: 10rpx;
		font-size: 34rpx;
		font-weight: bold;
	}


	.right {
		color: $u-type-warning-dark;
	}

	.progressBox {
		width: 150rpx;
		float: right;
	}



	.need-remark {
		color: #666;
		font-size: 28rpx;
	}

	.item {
		display: flex;
		margin: 20rpx 0 0;
	}

	.left {
		margin-right: 20rpx;
	}

	image {
		width: 260rpx;
		height: 190rpx;
		border-radius: 10rpx;
	}


	.content {
		margin-left: 10rpx;
	}

	.title {
		font-size: 28rpx;
		line-height: 45rpx;
	}

	.type {
		margin: 6rpx 0;
		font-size: 24rpx;
		color: $u-tips-color;
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 3;
		line-clamp: 3;
		-webkit-box-orient: vertical;
	}

	.delivery-time {
		color: #0081ff;
		font-size: 24rpx;
	}


	.right {
		margin-left: 10rpx;
		padding-top: 20rpx;
		text-align: right;
	}

	.decimal {
		font-size: 24rpx;
		margin-top: 4rpx;
	}

	.number {
		color: $u-tips-color;
		font-size: 24rpx;
	}


	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
	}

	.total-price {
		font-size: 32rpx;
	}


	.bottom {
		line-height: 90rpx;
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.btnBox {
		width: 150rpx;
		display: flex;
		justify-content: space-between;
	}

	.btn {
		line-height: 52rpx;
		width: 140rpx;
		border-radius: 12rpx;
		border: 2rpx solid $u-tips-color;
		font-size: 26rpx;
		text-align: center;
		color: $u-tips-color;
	}

	.evaluate {
		color: $u-type-primary;
		border-color: $u-type-primary;
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;
	}

	image {
		width: 300rpx;
		border-radius: 50%;
		margin: 0 auto;
	}

	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}

	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, #1cbbb4 0%, #0081ff 100%);
	}


	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
		background: #f1f1f1;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}



	.u-node {
		width: 44rpx;
		height: 44rpx;
		border-radius: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #d0d0d0;
	}

	.u-order-title {
		color: #333333;
		font-weight: bold;
		font-size: 32rpx;
	}

	.u-order-desc {
		color: rgb(150, 150, 150);
		font-size: 28rpx;
		margin-bottom: 6rpx;
	}

	.u-order-time {
		color: #000;
		font-size: 26rpx;
	}













	.u-node {
		width: 44rpx;
		height: 44rpx;
		border-radius: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #d0d0d0;
	}

	.u-order-title {
		color: #333333;
		font-weight: bold;
		font-size: 32rpx;
	}

	.u-order-desc {
		color: rgb(150, 150, 150);
		font-size: 28rpx;
		margin-bottom: 6rpx;
	}

	.u-order-time-2 {
		color: #aa0000;
		font-size: 26rpx;
	}


	.withdrawal-popup {
		padding: 30rpx;
		background-color: white;
		border-radius: 10rpx;
	}

	.popup-title {
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 20rpx;
		text-align: center;
	}

	u-input {
		margin-bottom: 20rpx;
	}

	.button-group {
		display: flex;
		justify-content: center;
		gap: 20rpx;
	}
</style>